﻿/*
 * NetUdpSystem.h
 */
#ifndef __GDK_NETUDPSYSTEM_H__
#define __GDK_NETUDPSYSTEM_H__

#include <gdk/net/Socket.h>
#include <gdk/net/NetUdpServer.h>
#include <gdk/net/NetUdpConnection.h>
#include <gdk/net/NetSystem.h>
#include <gdk/net/NetMessage.h>
#include <gdk/net/NetEvent.h>


namespace gdk
{

	///////////////////////////////////////////////
	class GDK_NET_EXPORT NetUdpSystem : public NetSystem
	{
		DECLARE_CLASS_HANDLE(NetUdpSystem)
		DECLARE_CLASS_INSTANCE1(NetUdpSystem, int16_t)

	private:
		uint16_t			_port;
		NetUdpServerPtr		_udpServer;

	private:
		NetUdpSystem(uint16_t port);
		~NetUdpSystem(void);

	public:
		virtual bool init(void);
		virtual void exit(void);
		//-----------------------------------------------------------------

	public:
		__INLINE__ uint16_t getPort(void) const { return _port; }
		//-----------------------------------------------------------------

	private:
		NetUdpConnectionPtr createUdpConnection(void);
		//-----------------------------------------------------------------
		void onAccept(const Evt_NetUdpAccept *evt);
		void onConnectOk(const Evt_NetUdpConnectOk *evt);
		void onConnectFail(const Evt_NetUdpConnectFail *evt);
		void onClosed(const Evt_NetUdpClosed *evt);
		void onError(const Evt_NetUdpError *evt);
		void onAbort(const Evt_NetUdpAbort *evt);
		void onReceive(const Evt_NetUdpReceive *evt);
		//-----------------------------------------------------------------
		void onNetConnect(NetConnect *msg);
		void onNetClose(NetClose *msg);
		void onNetSend(NetSend *msg);
		//-----------------------------------------------------------------
	};
	typedef NetUdpSystem::Handle NetUdpSystemPtr;


} //namespace gdk


#endif //__GDK_NETUDPSYSTEM_H__
